package handler

import (
	"fmt"
	"net/http"
	"shape-erver/internal/logic"
	"shape-erver/internal/svc"
	"shape-erver/internal/types"
	"shape-erver/utils/xhttp"

	"github.com/tal-tech/go-zero/rest/httpx"
)

func AddTaskHandler(ctx *svc.ServiceContext) http.HandlerFunc {
	fmt.Println("进到AddTaskHandler")
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.AddTaskReq
		if err := httpx.Parse(r, &req); err != nil {
			xhttp.ParamErrorResult(r, w, err)
			return
		}

		l := logic.NewAddTaskLogic(r.Context(), ctx)
		resp, err := l.AddTask(req)
		xhttp.HttpResult(r, w, resp, err)
	}
}
